#include "welcome.h"

#include <stdio.h>

//欢迎页面
lv_obj_t* welcome_page;

// 登录按钮
lv_obj_t* login_btn;

// 注册按钮
lv_obj_t* register_btn;

void to_login(lv_event_t* e){
    LV_LOG_INFO("To Register Page");
    welcome_page_destroy();
    login_page_display(); 
}

void to_register(lv_event_t* e){
    welcome_page_destroy();
    register_page_display();
}

void welcome_page_display(){
    // 创建欢迎页面
    welcome_page = lv_obj_create(lv_scr_act());
    // 设置界面大小
    lv_obj_set_size(welcome_page, LV_HOR_RES, LV_VER_RES);
    lv_obj_set_style_radius(welcome_page, 0, 0);
    lv_obj_set_style_border_width(welcome_page, 0, 0);
    lv_obj_set_style_outline_width(welcome_page, 0, 0);

    //创建背景对象
    static lv_style_t style_bg;
    lv_style_init(&style_bg);
    lv_style_set_bg_img_src(&style_bg, &origin_picture);
    lv_obj_add_style(welcome_page, &style_bg, LV_PART_MAIN);

    // 创建按钮区
    lv_obj_t* btn_area = lv_obj_create(welcome_page);
    lv_obj_set_size(btn_area, 290, 50);
    lv_obj_align(btn_area, LV_ALIGN_OUT_BOTTOM_MID, 240, 350);
    lv_obj_add_flag(btn_area, LV_OBJ_FLAG_HIDDEN);

    // 初始化login按钮
    login_btn = lv_btn_create(welcome_page);
    lv_obj_set_size(login_btn, 100, 50);
    lv_obj_align_to(login_btn, btn_area, LV_ALIGN_LEFT_MID, 0, 0);
    // 设置事件，传递输入框数据
    lv_obj_add_event_cb(login_btn, to_login, LV_EVENT_CLICKED, NULL);

    // 设置按钮标签
    lv_obj_t* login_label = lv_label_create(login_btn);
    lv_obj_align_to(login_label, login_btn, LV_ALIGN_LEFT_MID, 0, 0);
    lv_obj_set_style_text_font(login_label, &lv_font_montserrat_16, 0);
    lv_label_set_text(login_label, "Login");

    // 初始化register按钮
    register_btn = lv_btn_create(welcome_page);
    lv_obj_set_size(register_btn, 100, 50);
    lv_obj_align_to(register_btn, btn_area, LV_ALIGN_RIGHT_MID, 0, 0);
    lv_obj_add_event_cb(register_btn, to_register, LV_EVENT_CLICKED, NULL);

    // 设置按钮标签
    lv_obj_t* register_label = lv_label_create(register_btn);
    lv_obj_align_to(register_label, register_btn, LV_ALIGN_LEFT_MID, 0, 0);
    lv_obj_set_style_text_font(register_label, &lv_font_montserrat_16, 0);
    lv_label_set_text(register_label, "Register");
}

// 欢迎页面销毁
void welcome_page_destroy() {
    // 销毁界面元素
    lv_obj_del(welcome_page);
}